<?
class AdminVista
{


	var $negozio;
	var $user;
	var $template;


	// VARIABILI DI SOSTITUZIONE TEMPLATE PRINCIPALE
	var $header;
	var $footer;
	var $sidebar;
	var $content;
	//

	function AdminVista(&$negozio, &$user)
	{

		$this->negozio = &$negozio;
		$this->user = &$user;

		$this->template = '_admin/'.$_SERVER[HTTP_HOST].'/template/template.php';
		if(!file_exists($this->template)) $this->template = '_admin/_default/template/template.php';
	}
	
	function index()
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/index.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/index.php';
		include($file_tpl);
		$this->content = ob_get_contents();
		ob_end_clean();
	}
	function login($n_errors)
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/login.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/login.php';
		include($file_tpl);
		$this->content = ob_get_contents();
		ob_end_clean();
	}
	
	function prodList($categoria)
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/product_list.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/product_list.php';
		include($file_tpl);
		$this->content = ob_get_contents();
		ob_end_clean();
	}
	
	function prodIndex()
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/product_index.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/product_index.php';
		include($file_tpl);
		$this->content = ob_get_contents();
		ob_end_clean();
	}

	function editCat($categoria)
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/product_list.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/edit_cat.php';
		include($file_tpl);
		$this->content = ob_get_contents();
		ob_end_clean();
	}
	
	function anagrProd($categoria)
	{
		global $lang;
		$anagrafiche = $categoria->getAnagrafiche();
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/edit_anagr_prod.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/edit_anagr_prod.php';
		include($file_tpl);
		$this->content = ob_get_contents();
		ob_end_clean();
	}

	
	function editProd($prodotto)
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/edit_prod.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/edit_prod.php';
		include($file_tpl);
		$this->content = ob_get_contents();
		ob_end_clean();
	}
	
	function editPrezzi($prodotto)
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/edit_prezzi.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/edit_prezzi.php';
		include($file_tpl);
		$this->content = ob_get_contents();
		ob_end_clean();
	}
	
	function editConfig()
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/configure_index.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/configure_index.php';
		include($file_tpl);
		$this->content = ob_get_contents();
		ob_end_clean();
	}
	function editConfigGen()
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/configure_gen.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/configure_gen.php';
		include($file_tpl);
		$this->content = ob_get_contents();
		ob_end_clean();
	}
	function editConfigPag($metodo)
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/configure_pag.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/configure_pag.php';
		include($file_tpl);
		$this->content = ob_get_contents();
		ob_end_clean();
	}
	function editConfigSped($metodo)
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/configure_sped.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/configure_sped.php';
		include($file_tpl);
		$this->content = ob_get_contents();
		ob_end_clean();
	}
	
	function ordiniList($ordini)
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/orders_list.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/orders_list.php';
		include($file_tpl);
		$this->content = ob_get_contents();
		ob_end_clean();
	}
	
	function CliList($clienti)
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/cli_list.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/cli_list.php';
		include($file_tpl);
		$this->content = ob_get_contents();
		ob_end_clean();
	}
	
	function CliEdit($cliente)
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/cli_edit.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/cli_edit.php';
		include($file_tpl);
		$this->content = ob_get_contents();
		ob_end_clean();
	}
	
	
	


	function display()
	{
		global $lang;
		

		// includo menu principale
		//$this->menu_principale();
		//$this->menu_contesto();
		//if($this->negozio->messaggio||$this->carrello->messaggio||$this->ordine->messaggio)$this->messaggio();
		//$this->box_carrello();
		
		$this->header();
		$this->sidebar();
		$this->footer();

		ob_start();
		include($this->template);
		$html = ob_get_contents();
		ob_end_clean();
		return $html;
	}

	function header()
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/header.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/header.php';
		include($file_tpl);
		$this->header = ob_get_contents();
		ob_end_clean();
	}

	function sidebar()
	{
		global $lang;
		
		$cat_struct = $GLOBALS[cat_struct];
		
		ob_start();
		if($_REQUEST[pagina]=='prodotto' || $_REQUEST[pagina]=='categoria' || $_REQUEST[pagina]=='prezzi' || $_REQUEST[pagina]=='anagrafica_prod' )
		{
			$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/sidebar_prodotti.php';
			if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/sidebar_prodotti.php';
		}
		elseif($_REQUEST[pagina]=='configurazione' )
		{
			$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/sidebar_configure.php';
			if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/sidebar_configure.php';
		}
		else 
		{
			$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/sidebar_login.php';
			if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/sidebar_login.php';
		}
		include($file_tpl);
		$this->sidebar = ob_get_contents();
		ob_end_clean();
	}

	function footer()
	{
		global $lang;
		ob_start();
		$file_tpl = '_admin/'.$_SERVER[HTTP_HOST].'/template/footer.php';
		if(!file_exists($file_tpl)) $file_tpl = '_admin/_default/template/footer.php';
		include($file_tpl);
		$this->footer = ob_get_contents();
		ob_end_clean();
	}



	/* UTILITà*/
	function Truncate($string, $limit, $break=" ", $pad="...") {
		if(strlen($string) <= $limit) return $string;
		if(false !== ($breakpoint = strpos($string, $break, $limit))) { 
			if($breakpoint < strlen($string) - 1) { 
				$string = substr($string, 0, $breakpoint) . $pad; 
			} 
		} return $string; 
	}
	

}

?>